package com.qf.service.impl;

import com.qf.entity.Course;
import com.qf.entity.CourseTeacher;
import com.qf.entity.Teacher;
import com.qf.mapper.CourseMapper;
import com.qf.mapper.TeacherMapper;
import com.qf.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcx
 * @since 2020-09-03
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public List<CourseTeacher> selectCourseBy(Course course) {
        List<Course> courses = courseMapper.selectCourseBy(course);
        List<CourseTeacher> list = new ArrayList();
        if (courses != null && courses.size() != 0){
            for (Course cours : courses) {
                CourseTeacher courseTeacher = new CourseTeacher();
                Integer id = cours.getId();
                List<Teacher> teachers = teacherMapper.selectByCourseId(id);

                courseTeacher.setId(id);
                courseTeacher.setTitle(cours.getTitle());
                courseTeacher.setOriginnalPrice(cours.getOriginalPrice());
                courseTeacher.setCurrentPrice(cours.getCurrentPrice());
                courseTeacher.setSeason(cours.getSeason());
                courseTeacher.setAddress(cours.getAddress());
                courseTeacher.setTeachers(teachers);
                list.add(courseTeacher);
            }
        }

        return list;
    }
}
